package cn.com.egova.erp.action;

import cn.com.egova.erp.biz.IReturnorderdetailBiz;
import cn.com.egova.erp.biz.IReturnordersBiz;
import cn.com.egova.erp.entity.Emp;
import cn.com.egova.erp.entity.Returnorderdetail;
import cn.com.egova.erp.entity.Store;
import cn.com.egova.erp.exception.ErpException;
import cn.com.egova.erp.utils.FastJsonUtil;

/**
 * 退货订单明细Action
 *
 * @author Administrator
 */
public class ReturnorderdetailAction extends BaseAction<Returnorderdetail> {

    private IReturnorderdetailBiz returnorderdetailBiz;
    private IReturnordersBiz returnordersBiz;
    private Long storeuuid;

    public void setReturnorderdetailBiz(IReturnorderdetailBiz returnorderdetailBiz) {
        this.returnorderdetailBiz = returnorderdetailBiz;
        super.setBaseBiz(this.returnorderdetailBiz);
    }

    public void setReturnordersBiz(IReturnordersBiz returnordersBiz) {
        this.returnordersBiz = returnordersBiz;
    }

    public Long getStoreuuid() {
        return storeuuid;
    }

    public void setStoreuuid(Long storeuuid) {
        this.storeuuid = storeuuid;
    }

    /**
     * 根据订单明细ID获取对应的仓库
     */
    public void getStoreByID() {
        try {
            Store store = returnordersBiz.getStoreByID(getId());
            FastJsonUtil.ajaxReturn(true, "查询仓库成功!", store);
        } catch (Exception e) {
            e.printStackTrace();
            FastJsonUtil.ajaxReturn(false, "查询仓库失败!", null);
        }
    }

    /**
     * 采购退货单出库
     */
    public void doOutStore() {
        Emp loginUser = getLoginUser();
        if (loginUser == null) {
            ajaxReturn(false, "请先登录!");
            return;
        }
        try {
            returnorderdetailBiz.doOutStore(getId(), storeuuid, loginUser.getUuid());
            ajaxReturn(true, "出库成功!");
        } catch (ErpException e) {
            ajaxReturn(false, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            ajaxReturn(false, "出库失败!");
        }
    }


    /**
     * 销售退货单入库
     */
    public void doInStore() {
        Emp loginUser = getLoginUser();
        if (null == loginUser) {
            ajaxReturn(false, "请先登录!");
            return;
        }
        try {
            //getId()这里指的是订单明细的id，是前端通过隐藏域传递过来的(orders.html)。
            returnorderdetailBiz.doInStore(getId(), storeuuid, loginUser.getUuid());
            ajaxReturn(true, "入库成功!");
        } catch (ErpException e) {
            ajaxReturn(false, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            ajaxReturn(false, "入库失败!");
        }
    }
}
